package com.quickask.operate.qiniu;

import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import com.quickask.operate.data.Constants;

/**
 * Created by NaSa on 2015/9/24.
 */
public class GenerateUploadToken {

    private Auth auth = Auth.create(Constants.QINIU_ACCESS_KEY, Constants.QINIU_SECRET_KEY);

    //简单上传,使用默认策略
    public String getUpToken0() {
        return auth.uploadToken(Constants.QINIU_BUCKET_NAME);
    }

    // 覆盖上传
    public String getUpToken1(){
        return auth.uploadToken(Constants.QINIU_BUCKET_NAME, "key");
    }

    // 设置指定上传策略
    public String getUpToken2(){
        return auth.uploadToken(Constants.QINIU_BUCKET_NAME, null, 3600, new StringMap()
                .put("callbackUrl", "call back url").putNotEmpty("callbackHost", "")
                .put("callbackBody", "key=$(key)&hash=$(etag)"));
    }

    // 设置预处理、去除非限定的策略字段
    public String getUpToken3(){
        return auth.uploadToken("bucket", null, 3600, new StringMap()
                .putNotEmpty("persistentOps", "").putNotEmpty("persistentNotifyUrl", "")
                .putNotEmpty("persistentPipeline", ""), true);
    }

}
